﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using ProductManagement.Domain;
using ProductManagement.Domain.Shared;

namespace ProductManagement.EntityFrameworkCore
{
    public class CategoryMapping : IEntityTypeConfiguration<Category>
    {
        public void Configure(EntityTypeBuilder<Category> b)
        {
            //b.ConfigureByConvention();
            //b.AuditMapping<Order, long>(OrderConst.ColumnPrefix);
            b.ToTable("tgoodscategory");
            
            b.Property(q => q.Id).IsRequired().HasComment("主键Id").HasColumnType("bigint").ValueGeneratedNever();
            b.Property(q => q.Title).IsRequired().HasMaxLength(20).HasComment("分类名称");
            b.Property(q => q.Sort).IsRequired().HasComment("排序").HasDefaultValue(0);
            b.Property(q => q.Type).HasComment("分类业务类型").HasMaxLength(20)
                                   .HasConversion(obj => obj.Value.ToLower(), str => CategoryTypeEnum.FromValue(str));

        }
    }
}